package com.yuetong.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.business.domain.YtArea;
import com.yuetong.business.service.IYtAreaService;
import com.yuetong.common.utils.poi.ExcelUtil;

/**
 * 区域Controller
 * 
 * @author  卓晓君
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/business/area")
public class YtAreaController extends BaseController
{
    @Autowired
    private IYtAreaService ytAreaService;

    /**
     * 查询区域列表
     */
    @PreAuthorize("@ss.hasPermi('business:area:list')")
    @GetMapping("/list")
    public AjaxResult list(YtArea ytArea)
    {
        List<YtArea> list = ytAreaService.selectYtAreaList(ytArea);
        return success(list);
    }

    /**
     * 导出区域列表
     */
    @PreAuthorize("@ss.hasPermi('business:area:export')")
    @Log(title = "区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtArea ytArea)
    {
        List<YtArea> list = ytAreaService.selectYtAreaList(ytArea);
        ExcelUtil<YtArea> util = new ExcelUtil<YtArea>(YtArea.class);
        util.exportExcel(response, list, "区域数据");
    }

    /**
     * 获取区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ytAreaService.selectYtAreaById(id));
    }

    /**
     * 新增区域
     */
    @PreAuthorize("@ss.hasPermi('business:area:add')")
    @Log(title = "区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtArea ytArea)
    {
        return toAjax(ytAreaService.insertYtArea(ytArea));
    }

    /**
     * 修改区域
     */
    @PreAuthorize("@ss.hasPermi('business:area:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtArea ytArea)
    {
        return toAjax(ytAreaService.updateYtArea(ytArea));
    }

    /**
     * 删除区域
     */
    @PreAuthorize("@ss.hasPermi('business:area:remove')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ytAreaService.deleteYtAreaByIds(ids));
    }
}
